package controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import dto.UserDto;

@Controller
public class MoveController {
	
	@RequestMapping(value = "/index.html", method = RequestMethod.GET)
	public ModelAndView indexGo(HttpServletRequest request) {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("index");
		return modelAndView;
	}
	
	@RequestMapping(value = "/calendar.html", method = RequestMethod.GET)
	public ModelAndView schedule() {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("index");
		modelAndView.addObject("content", "/schedule/calendar.jsp");
		return modelAndView;
	}
	
	
	@RequestMapping(value = "/moveLogout.html", method = RequestMethod.GET)
	public ModelAndView movelogout(HttpSession session){
		ModelAndView modelAndView = new ModelAndView();
		String loginName = (String)session.getAttribute("loginName");
		modelAndView.addObject("name", loginName);
		modelAndView.addObject("content", "/WEB-INF/member/logoutsuccess.jsp");
		modelAndView.setViewName("index");
		session.invalidate();
		return modelAndView;
	}
	
	@RequestMapping(value = "/moveLoginForm.html", method = RequestMethod.GET)
	public ModelAndView moveLoginForm(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("content", "/WEB-INF/member/loginForm.jsp");
		modelAndView.setViewName("index");
		return modelAndView;
	}
	
	@RequestMapping(value = "/moveJoinForm.html", method = RequestMethod.GET)
	public ModelAndView moveJoinForm(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("content", "/WEB-INF/member/joinForm.jsp");
		modelAndView.setViewName("index");
		return modelAndView;
	}
	
	@RequestMapping(value = "/moveMemberInfo.html", method = RequestMethod.GET)
	public ModelAndView moveMemberInfoForm(HttpSession session){
		ModelAndView modelAndView = new ModelAndView();
		Map<String, Object> model = new HashMap<String, Object>();
		UserDto userInfo = (UserDto) session.getAttribute("loginUser");
		String email1 = userInfo.getEmail().split("@")[0];
		String email2 = userInfo.getEmail().split("@")[1];
		
		String phone1 = userInfo.getPhone().split("-")[0];
		String phone2 = userInfo.getPhone().split("-")[1];
		String phone3 = userInfo.getPhone().split("-")[2];
		model.put("email1", email1);
		model.put("email2", email2);
		
		model.put("phone1", phone1);
		model.put("phone2", phone2);
		model.put("phone3", phone3);
		model.put("content", "/WEB-INF/member/infoForm.jsp");
		modelAndView.addAllObjects(model);
		modelAndView.setViewName("index");
		return modelAndView;
	}
	
	@RequestMapping(value = "/moveDeleteForm.html", method = RequestMethod.GET)
	public ModelAndView moveDeleteForm(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("content", "/WEB-INF/member/pw_check.jsp");
		modelAndView.setViewName("index");
		return modelAndView;
	}
	
}
